package activiti;

import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.util.List;


/**
 * @author Raih
 * @Date 2020/5/22
 */
public class Test {

    public static void main(String[] args) {

        ProcessEngine pe= ProcessEngines. getDefaultProcessEngine();
        RepositoryService res=pe. getRepositoryService();
        RuntimeService rus=pe. getRuntimeService();
        TaskService ts=pe. getTaskService();
        Deployment dep=res. createDeployment(). addClasspathResource("vacationRequest. bpmn"). deploy();
    //ProcessDefinition pb=res. createProcessDefinitionQuery(). deploymentId(dep. getId()). singleResult();
        ProcessInstance pi=rus. startProcessInstanceByMessage("My Message");
        Task queryTask=ts. createTaskQuery().processInstanceId((pi. getId())).singleResult();
        System. out. println("Process Instance Information:");
        ProcessInstance queryPI=rus. createProcessInstanceQuery(). processInstanceId(pi. getId()). singleResult();
        System. out. println("Process InstanceID:"+queryPI. getId()+", Process Definition ID:"+queryPI.getProcessDefinitionId());
        System. out. println("Exection Information:");
        List<Execution> exes=rus. createExecutionQuery(). processInstanceId(pi. getId()).list();
        for(Execution exe: exes) {
            System.out.println("Exection ID:" + exe.getId() + ", Process Instance ID:" + exe.getProcessInstanceId() + "Activity");
        }
        System. out. println("Task["+queryTask. getName()+"] is finished.");

    }


}
